<template>
  <div id="contentExamined">
    <h1 class="con-right-title">
      阅读内容审核
    </h1>
    <div class="bottom-box">
      <div class="table">
        <!-- 上部搜索条件 -->
        <topSearch :form-inline="formInline" @toSearch="toSearch"></topSearch>
        <div class="table-conBtn">
          <el-button
            v-permission="'wh:system:readContentExamined:adopt'"
            type="warning"
            icon="el-icon-check"
            @click="handlePass('PUBDISPLAY')"
          >
            公开展示
          </el-button>
          <el-button
            v-permission="'wh:system:readContentExamined:adopt'"
            type="warning"
            icon="el-icon-check"
            @click="handlePass('HOMEPAGEONLY')"
          >
            仅主页展示
          </el-button>
          <el-button
            v-permission="'wh:system:readContentExamined:noadopt'"
            type="warning"
            icon="el-icon-close"
            plain
            @click="notPass()"
          >
            不通过
          </el-button>
          <freshCom @searchList="searchList"></freshCom>
          <selectColumn
            ref="selectCum"
            @setColumn="setColumns"
            :nameList="columnList"
          ></selectColumn>
        </div>
        <!-- 表格部分 -->
        <el-table
          v-loading="loading"
          :data="tableData"
          stripe
          style="width: 100%;"
          @selection-change="handleSelectionChange"
          max-height="490"
          ref="table"
        >
          <el-table-column
            type="selection"
            width="50"
            align="center"
            :selectable="selectAble"
          ></el-table-column>
          <el-table-column type="index" width="50" align="center" label="序号">
            <template slot-scope="scope">
              {{
                scope.$index
                  | filterPage(searchParams.pageNum, searchParams.pageSize)
              }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.nickname"
            label="昵称"
            prop="user.nickname"
            min-width="80"
          >
            <template slot-scope="scope">
              {{
                scope.row.user && scope.row.user.nickname
                  ? scope.row.user.nickname
                  : ''
              }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.dpAccount"
            label="大鹏号"
            prop="user.dpAccount"
            min-width="80"
          >
            <template slot-scope="scope">
              {{
                scope.row.user.dpAccount && scope.row.user.dpAccount
                  ? scope.row.user.dpAccount
                  : ''
              }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.publishDate"
            label="发布时间"
            prop="publishDate"
            width="150"
          >
            <template slot-scope="scope">
              {{ scope.row.publishDate }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.title"
            label="标题"
            prop="title"
            min-width="80"
          >
            <template slot-scope="scope">
              <span
                v-if="scope.row.title"
                v-html="filterContent(scope.row.title)"
                >{{ scope.row.title }}</span
              >
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.college"
            label="学院"
            prop="college"
            min-width="80"
          >
            <template slot-scope="scope">
              <span
                v-if="scope.row.college"
                class="tag-span"
                :class="scope.row.college | filterClass('readCollegeType')"
                >{{ scope.row.college | filterName('readCollegeType') }}</span
              >
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.covers"
            label="视图内容"
            width="100"
            align="center"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.covers && scope.row.covers.length > 0">
                <listImgShow :imgInfo="scope.row.covers"></listImgShow>
              </span>
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.createDate"
            label="创建时间"
            prop="createDate"
            width="150"
          >
            <template slot-scope="scope">
              {{ scope.row.createDate }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.labelPrope"
            label="显性标签"
            prop="labelPrope"
            min-width="260"
          >
            <template slot-scope="scope">
              <explicitTag
                :labels="scope.row.labels"
                :showContentId="scope.row.id"
                @refresh="refresh"
              ></explicitTag>
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.rebutNum"
            label="文章驳回次数"
            prop="rebutNum"
            align="center"
            width="120"
          >
            <template slot-scope="scope">
              {{ scope.row.rebutNum }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.userProperty"
            label="用户属性"
            prop="userProperty"
            width="80"
          >
            <template slot-scope="scope">
              <span
                v-if="scope.row.userProperty"
                class="tag-span"
                :class="scope.row.userProperty | filterClass('readConUserAttr')"
                >{{
                  scope.row.userProperty | filterName('readConUserAttr')
                }}</span
              >
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.autoVerifyDate"
            label="机审时间"
            prop="autoVerifyDate"
            width="150"
          >
            <template slot-scope="scope">
              {{ scope.row.verifyRecord.autoVerifyDate | timeToTime }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.autoVerifyStatus"
            label="机审结果"
            prop="autoVerifyStatus"
            width="90"
          >
            <template slot-scope="scope">
              <span
                v-if="scope.row.verifyRecord.autoVerifyStatus === 'PASS'"
                class="tag-span primary"
                >通过</span
              >
              <span
                v-if="scope.row.verifyRecord.autoVerifyStatus === 'REJECT'"
                class="tag-span danger hand"
                >未通过</span
              >
              <span
                v-if="scope.row.verifyRecord.autoVerifyStatus === 'PENDING'"
                class="tag-span default"
                >未审核</span
              >
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.verifyStatus"
            label="人工审核结果"
            prop="verifyStatus"
            width="110"
          >
            <template slot-scope="scope">
              <span
                v-if="scope.row.verifyRecord"
                class="tag-span"
                :class="
                  scope.row.verifyRecord.verifyStatus
                    | filterClass('readAuditStatus')
                "
                >{{
                  scope.row.verifyRecord.verifyStatus
                    | filterName('readAuditStatus')
                }}</span
              >
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.showType"
            label="展示方式"
            prop="showType"
            width="90"
          >
            <template slot-scope="scope">
              <span
                v-if="scope.row.showType"
                class="tag-span"
                :class="scope.row.showType | filterClass('showType')"
                >{{ scope.row.showType | filterName('showType') }}</span
              >
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.auditingName"
            label="审核人"
            prop="auditingName"
            min-width="80"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.auditingName">
                {{ scope.row.auditingName }}</span
              >
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="columnSHow.verifyDate"
            label="人工审核时间"
            prop="verifyDate"
            width="150"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.verifyRecord.verifyDate">
                {{ scope.row.verifyRecord.verifyDate }}</span
              >
              <span v-else>-</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="140">
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.verifyRecord.verifyStatus === 'REJECT'"
                type="text"
                @click="showFailReason(scope.row)"
              >
                未通过理由
              </el-button>
              <el-button
                v-permission="'wh:system:readContentExamined:detail'"
                v-if="filterSHowBtn(scope.row.verifyRecord.verifyStatus)"
                type="text"
                @click="handleDetail(scope.row.id)"
              >
                查看详情
              </el-button>
              <el-button
                v-permission="'wh:system:readContentExamined:delete'"
                v-if="filterSHowBtn(scope.row.verifyRecord.verifyStatus)"
                type="text"
                @click="deleteWork(scope.row.id)"
              >
                删除
              </el-button>
              <el-button
                v-permission="'wh:system:readContentExamined:check'"
                v-if="scope.row.verifyRecord.verifyStatus === 'PENDING'"
                type="text"
                @click="showEdit(scope.row)"
              >
                审核
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-全局组件-->
        <pageCom
          :searchParams="searchParams"
          :total="total"
          @searchList="searchList"
        ></pageCom>
        <!---查看详情-->
        <dialogReadDetail
          v-if="dialogData.isShow"
          :dialog-data="dialogData"
        ></dialogReadDetail>
        <!-- 不通过理由弹窗 -->
        <del-dialog
          :del-dialog-data="delDialogData"
          v-if="delDialogData.isShow"
          @reasonDel="failRequest"
        ></del-dialog>
        <!--审核阅读-->
        <dialogPubRead
          v-if="dialogPubReadData.isShow"
          :dialog-data="dialogPubReadData"
          @refresh="refresh"
        ></dialogPubRead>
      </div>
    </div>
  </div>
</template>

<script>
import topSearch from '@component/readManagement/readCheck/topSearch' // 上部搜索条件
import { contentToStr } from '@utils/pubFunction'
import delDialog from '@common/delDialog' // 不通过理由弹窗
import dialogReadDetail from '@component/readManagement/common/dialogReadDetail' //预览弹窗
import dialogPubRead from '@component/readManagement/readMine/dialogPubRead' // 编辑阅读
import { getReadsList, putReads } from '@/api/readManagement/readCheck'
import { saveScrollMixins } from '@/mixins/saveScroll'
import { columnMixin } from '@/mixins/columnShowHide'
import explicitTag from '@common/explicitTag'

export default {
  name: 'check',
  msg: '',
  mixins: [saveScrollMixins, columnMixin],
  components: {
    topSearch,
    dialogReadDetail,
    delDialog,
    explicitTag,
    dialogPubRead
  },
  data() {
    return {
      loading: false,
      total: 0, // 搜索条件
      alldisabled: true, // 公开展示按钮禁用状态
      mdisabled: true, // 仅主页展示按钮禁用状态
      notdisabled: true, // 不通过按钮禁用状态
      formInline: {
        manualVerify: '', // 人审结果
        autoVerify: '', // 机审结果
        orderWay: '',
        content: '',
        userType: '',
        userValue: '',
        verifyUserId: '', // 审核人
        showType: '', // 展示方式
        startTime: '',
        endTime: '',
        pubStartTime: '',
        pubEndTime: '',
        userProperty: '', // 用户属性
        college: ''
      },
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10 // 页面显示条数
      },
      multipleSelection: [],
      powerStr: 'system:readContentExamined:list', // 是否查询的标识
      powerAry: [], // 可显示的权限
      canShowPage: false, // 是否显示当前页面
      // 表格数据
      tableData: [],
      // 查看详情
      dialogData: {
        isShow: false, // 默认隐藏
        params: '' // 编辑时，传递的参数
      },
      delDialogData: {
        isShow: false,
        params: '',
        type: '不通过'
      },
      dialogPubReadData: {
        // 编辑阅读
        isShow: false, // 默认隐藏
        isFromCheck: true, // 是否来自内容审核
        id: ''
      },
      columnList: [
        { label: '昵称', value: 'nickname' },
        { label: '大鹏号', value: 'dpAccount' },
        { label: '发布时间', value: 'publishDate' },
        { label: '标题', value: 'title' },
        { label: '学院', value: 'college' },
        { label: '视图内容', value: 'covers' },
        { label: '创建时间', value: 'createDate' },
        { label: '显性标签', value: 'labelPrope' },
        { label: '文章驳回次数', value: 'rebutNum' },
        { label: '用户属性', value: 'userProperty' },
        { label: '机审时间', value: 'autoVerifyDate' },
        { label: '机审结果', value: 'autoVerifyStatus' },
        { label: '人工审核结果', value: 'verifyStatus' },
        { label: '展示方式', value: 'showType' },
        { label: '审核人', value: 'auditingName' },
        { label: '人工审核时间', value: 'verifyDate' }
      ]
    }
  },
  activated() {
    this.toTableScrollHeight()
  },
  mounted() {
    this.searchList()
    // 获取权限
    // this.getPower()
    this.$nextTick(() => {
      setTimeout(() => {
        this.setTableScrollHeight()
        this.$refs['selectCum'].setChoose(this.columnAry)
      }, 1000)
    })
  },
  methods: {
    /* 获取权限 */
    getPower() {
      let id = this.$route.query.mId
      this.getCurPageMenu(id).then((res) => {
        this.powerAry = res
        this.canShowPage = true
        if (!res.includes(this.powerStr)) {
          this.alertPower(this.powerStr)
          return false
        }
        this.searchList()
      })
    },
    //筛选是否显示操作按钮
    filterSHowBtn(status) {
      return status === 'PASS' || status === 'REBUT'
      // return status === 'PENDING' || status === 'REBUT'
    },
    /* 获取列表 */
    searchList() {
      this.loading = true
      let obj = Object.assign({}, this.searchParams, this.formInline)
      delete obj.createTime
      obj.listType = 'VERIFY'
      getReadsList(
        obj,
        (response) => {
          this.loading = false
          this.tableData = response.rows
          this.total = response.total
        },
        (response) => {
          this.loading = false
          this.message({
            message: response.message,
            type: 'warning'
          })
        }
      )
    },
    // table选择
    handleSelectionChange(val) {
      this.multipleSelection = val
      this.alldisabled = false
      this.mdisabled = false
      this.notdisabled = false
      if (this.multipleSelection.length === 0) {
        this.notdisabled = true
        this.alldisabled = true
        this.mdisabled = true
      }
    },
    /* 过滤返回评论内容 */
    filterContent(item) {
      return contentToStr(item)
    },
    // 查看详情
    handleDetail(id) {
      this.dialogData.isShow = true
      this.dialogData.params = id
    },
    // 批量公开展示/仅主页展示
    handlePass(type) {
      if (this.multipleSelection.length <= 0) {
        this.$message.warning('请至少选择一条数据！')
        return
      }
      this.$confirm(
        `确认要审核通过选中的${this.multipleSelection.length}条数据吗?`,
        '系统提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        let articleIds = []
        let ids = []
        this.multipleSelection.forEach((item) => {
          articleIds.push(item.id)
        })
        let data = {
          articleIds,
          type,
          verifyStatus: 'PASS'
        }
        putReads(data, (response) => {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.searchList()
        })
      })
    },
    // 单个公开展示/仅首页展示
    singlePublicPass(type, id) {
      let articleIds = []
      articleIds.push(id)
      let data = {
        articleIds,
        type,
        verifyStatus: 'PASS'
      }
      this.$confirm('确定审核通过该条阅读内容审核信息吗？', '通过提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          putReads(data, (response) => {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.searchList()
          })
        })
        .catch(() => {})
    },
    // 删除
    deleteWork(id) {
      this.id = id
      this.isDelete = true
      this.delDialogData.isShow = true
      this.delDialogData.type = '删除'
    },
    /* 批量不通过 */
    notPass() {
      if (this.multipleSelection.length <= 0) {
        this.$message.warning('请至少选择一条数据！')
        return
      }
      let ids = []
      this.multipleSelection.forEach((item) => {
        ids.push(item.id)
      })
      this.id = ids.join(',')
      this.delDialogData.isShow = true
    },
    /* 不通过单个 */
    handlNotPassWord(id) {
      this.id = id
      this.delDialogData.isShow = true
      this.delDialogData.type = '不通过'
    },
    // 子组件不通过事件
    failRequest(reason) {
      let ids = []
      ids = this.id.split(',')
      if (this.isDelete) {
        this.deleteReads(ids, reason)
      } else {
        this.noPassRequest(ids, reason)
      }
    },
    // 删除内容
    deleteReads(ids, reason) {
      let type = this.delDialogData.type
      this.$confirm(
        `${type}理由：${reason} 确认${type}该条信息？`,
        '系统提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        let params = {
          articleIds: ids,
          reason,
          verifyStatus: 'REJECT'
        }
        putReads(params, (response) => {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.searchList()
        })
      })
    },
    // 不通过多条请求
    noPassRequest(ids, reason) {
      let type = this.delDialogData.type
      this.$confirm(
        `${type}理由：${reason} 确认${type}该条信息？`,
        '系统提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        let params = {
          articleIds: ids,
          reason,
          verifyStatus: 'REJECT'
        }
        putReads(params, (response) => {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.searchList()
        })
      })
    },
    // 显示未通过理由
    showFailReason(row) {
      this.$alert(row.verifyRecord.manualReason, '不通过理由', {
        showConfirmButton: false
      }).catch(() => {})
    },
    /* 编辑弹窗显示 */
    showEdit(item) {
      this.dialogPubReadData.isShow = true
      this.dialogPubReadData.isFromCheck = true
      this.dialogPubReadData.id = item.id
    },
    /* 搜索 */
    toSearch() {
      this.searchParams.pageNum = 1
      this.searchList()
    },
    /* 刷新列表 */
    refresh() {
      this.toSearch()
    },
    selectAble(row, index) {
      if (
        row.verifyRecord.verifyStatus === 'PENDING' ||
        row.verifyRecord.verifyStatus === 'REBUT'
      ) {
        return true
      } else {
        return false
      }
    }
  }
}
</script>

<style lang="less">
#contentExamined {
  @import url('~@common/style/imgBox.less');
}
</style>
